/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FormTPenjualan.java
 *
 * Created on Feb 2, 2011, 4:38:57 PM
 */

package juwita;

import config.DBConnection;
import java.awt.CardLayout;
import java.sql.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.JOptionPane;

//buat date
import java.util.Date;
import java.text.DateFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.Locale;
import javax.swing.table.TableColumn;


/**
 *
 * @author Abah
 */
public class FormTPenjualan extends javax.swing.JInternalFrame {

    private DefaultTableModel DftTabModeTr;
    private DefaultTableModel DftTabModeBrg;
    private DefaultTableModel DftTabModeDBrg;
    private DefaultTableModel DftTabModePlg;
    private DefaultTableModel DftTabModeDPlg;
    java.sql.Connection conn = new DBConnection().connect();
    //int noData; //buat adddata
    //int x;
    int noItem = 0; //buat adddata    

    int[] aBal;
    int[] aSlop;
    int[] aBks;

    Integer iHTotal = 0;
    Integer iHDiskonBrg = 0;
    Integer iHTotal2 = 0;
    Integer iHDiskonPlg = 0;
    Integer iHAkhir = 0;
    Integer iHDibayar = 0;
    Integer iHKembali = 0;
    Integer iUangMuka = 0;
    Integer iSisaBayar = 0;

    String sTglJual;

    /** Creates new form FormTPenjualan */
    public FormTPenjualan() {
        initComponents();
        dcTglJual.setDate(getDateTime());
        
        Object[] Baris={"No","Kode","Nama Barang","Harga(Rp)","Bal","Slop","Bks","Total(Rp)"};
        DftTabModeTr=new DefaultTableModel(null,Baris);
        tbTransaksi.setModel(DftTabModeTr);

        aBal = new int[100];
        aSlop = new int[100];
        aBks = new int[100];

        setKdJual();

        iHTotal = 0;
        iHDiskonBrg = 0;
        iHTotal2 = 0;
        iHDiskonPlg = 0;
        iHAkhir = 0;
        iHDibayar = 0;
        iHKembali = 0;
        iUangMuka = 0;
        iSisaBayar = 0;

        /* to RP inialization */
        txtSubtotal.setText(toRp(0));
        txtHargaTotal.setText(toRp(iHTotal));
        txtHargaDiscountBrg.setText(toRp(iHDiskonBrg));
        txtHargaTotal2.setText(toRp(iHTotal2));
        txtHargaDiscountPlg.setText(toRp(iHDiskonPlg));
        txtHargaAkhir.setText(toRp(iHAkhir));
        txtHargaDibayar.setText(toRp(iHDibayar));
        txtHargaKembali.setText(toRp(iHKembali));
        txtUangMuka.setText(toRp(iUangMuka));
        txtSisaBayar.setText(toRp(iSisaBayar));
        //tampilData();

        lblUangMuka.setVisible(false);
        txtUangMuka.setVisible(false);
        lblSisa.setVisible(false);
        txtSisaBayar.setVisible(false);
        
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pnTengah = new javax.swing.JPanel();
        pnAtas = new javax.swing.JPanel();
        txtNamaBrg = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        txtKdBrg = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        cbTipeHarga = new javax.swing.JComboBox();
        txtNamaPlg = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        txtKdJual = new javax.swing.JTextField();
        txtDiscBrgRp = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        txtDiscBrgPrs = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        txtKdPlg = new javax.swing.JTextField();
        btnCariBrg = new javax.swing.JButton();
        jLabel9 = new javax.swing.JLabel();
        txtSlop = new javax.swing.JTextField();
        txtHarga = new javax.swing.JTextField();
        txtDiscPlgRp = new javax.swing.JTextField();
        txtDiscPlgPrs = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        btnCariPlg = new javax.swing.JButton();
        btnAdd = new javax.swing.JButton();
        txtBal = new javax.swing.JTextField();
        txtBks = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        txtSubtotal = new javax.swing.JTextField();
        jLabel16 = new javax.swing.JLabel();
        txtBalDB = new javax.swing.JTextField();
        jLabel17 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        txtSlopDB = new javax.swing.JTextField();
        jLabel19 = new javax.swing.JLabel();
        txtBksDB = new javax.swing.JTextField();
        jLabel20 = new javax.swing.JLabel();
        dcTglJual = new com.toedter.calendar.JDateChooser();
        jLabel23 = new javax.swing.JLabel();
        pnShow = new javax.swing.JPanel();
        pnTransaksi = new javax.swing.JPanel();
        spTransaksi = new javax.swing.JScrollPane();
        tbTransaksi = new javax.swing.JTable();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        txtHargaAkhir = new javax.swing.JTextField();
        txtHargaTotal = new javax.swing.JTextField();
        txtHargaDiscountBrg = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        txtHargaDibayar = new javax.swing.JTextField();
        txtHargaKembali = new javax.swing.JTextField();
        btnTrOk = new javax.swing.JButton();
        btnTrCancel = new javax.swing.JButton();
        btnTrNew = new javax.swing.JButton();
        lblSisa = new javax.swing.JLabel();
        txtHargaDiscountPlg = new javax.swing.JTextField();
        jLabel22 = new javax.swing.JLabel();
        txtHargaTotal2 = new javax.swing.JTextField();
        jLabel24 = new javax.swing.JLabel();
        txtSisaBayar = new javax.swing.JTextField();
        cbStatusBayar = new javax.swing.JComboBox();
        jLabel25 = new javax.swing.JLabel();
        txtUangMuka = new javax.swing.JTextField();
        lblUangMuka = new javax.swing.JLabel();
        pnBarang = new javax.swing.JPanel();
        pnCrBrg = new javax.swing.JPanel();
        spBarang = new javax.swing.JScrollPane();
        tbBarang = new javax.swing.JTable();
        pnAtas1 = new javax.swing.JPanel();
        btnShowAllBrg = new javax.swing.JButton();
        txtNmSrcBrg = new javax.swing.JTextField();
        cbSrcBrg = new javax.swing.JComboBox();
        btnSearchBrg = new javax.swing.JButton();
        lblCloseBrg = new javax.swing.JLabel();
        infoBrg = new javax.swing.JLabel();
        pnPelanggan = new javax.swing.JPanel();
        pnCrPlg = new javax.swing.JPanel();
        spPlg = new javax.swing.JScrollPane();
        tbPlg = new javax.swing.JTable();
        pnAtas2 = new javax.swing.JPanel();
        btnShowAllPlg = new javax.swing.JButton();
        txtNmSrcPlg = new javax.swing.JTextField();
        cbSrcPlg = new javax.swing.JComboBox();
        btnSearchPlg = new javax.swing.JButton();
        lblClosePlg = new javax.swing.JLabel();
        infoPlg = new javax.swing.JLabel();
        pnDBarang = new javax.swing.JPanel();
        infoDBrg = new javax.swing.JLabel();
        pnDPlg = new javax.swing.JPanel();
        infoDPlg = new javax.swing.JLabel();

        setBackground(new java.awt.Color(255, 255, 255));
        setClosable(true);
        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setIconifiable(true);
        setMaximizable(true);
        setResizable(true);
        setTitle("Transaksi Penjualan");
        setFrameIcon(new javax.swing.ImageIcon(getClass().getResource("/resource/penjualan.png"))); // NOI18N
        setPreferredSize(new java.awt.Dimension(631, 781));
        addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
            public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
                formInternalFrameClosing(evt);
            }
            public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
            }
        });

        pnTengah.setBackground(new java.awt.Color(255, 255, 255));
        pnTengah.setLayout(new java.awt.BorderLayout());

        pnAtas.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0), 2));
        pnAtas.setPreferredSize(new java.awt.Dimension(410, 250));
        pnAtas.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        txtNamaBrg.setEditable(false);
        pnAtas.add(txtNamaBrg, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 90, 230, -1));

        jLabel2.setText("Kode Barang");
        pnAtas.add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 60, -1, -1));

        txtKdBrg.setEditable(false);
        txtKdBrg.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtKdBrg.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtKdBrgKeyReleased(evt);
            }
        });
        pnAtas.add(txtKdBrg, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 60, 110, -1));

        jLabel3.setText("Kode Jual");
        pnAtas.add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 11, -1, -1));

        cbTipeHarga.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Kanvas", "Grosir", "Stokis" }));
        cbTipeHarga.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cbTipeHargaItemStateChanged(evt);
            }
        });
        pnAtas.add(cbTipeHarga, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 120, 70, -1));

        txtNamaPlg.setEditable(false);
        txtNamaPlg.setForeground(new java.awt.Color(0, 0, 204));
        pnAtas.add(txtNamaPlg, new org.netbeans.lib.awtextra.AbsoluteConstraints(420, 10, 160, -1));

        jLabel5.setText("Nama Barang");
        pnAtas.add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 90, -1, -1));

        jLabel6.setForeground(new java.awt.Color(0, 0, 204));
        jLabel6.setText("Discount ");
        pnAtas.add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(290, 30, -1, -1));

        txtKdJual.setEditable(false);
        txtKdJual.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtKdJual.setText("JL-0000001");
        pnAtas.add(txtKdJual, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 10, 80, -1));

        txtDiscBrgRp.setEditable(false);
        txtDiscBrgRp.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtDiscBrgRp.setText("0");
        pnAtas.add(txtDiscBrgRp, new org.netbeans.lib.awtextra.AbsoluteConstraints(180, 150, 100, 20));

        jLabel7.setForeground(new java.awt.Color(0, 0, 204));
        jLabel7.setText("Pelanggan");
        pnAtas.add(jLabel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(290, 10, -1, -1));

        txtDiscBrgPrs.setEditable(false);
        txtDiscBrgPrs.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtDiscBrgPrs.setText("0");
        pnAtas.add(txtDiscBrgPrs, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 150, 40, 20));

        jLabel8.setText("bal");
        pnAtas.add(jLabel8, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 180, -1, -1));

        txtKdPlg.setEditable(false);
        txtKdPlg.setForeground(new java.awt.Color(0, 0, 204));
        pnAtas.add(txtKdPlg, new org.netbeans.lib.awtextra.AbsoluteConstraints(360, 10, 60, -1));

        btnCariBrg.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resource/search.png"))); // NOI18N
        btnCariBrg.setText("Cari");
        btnCariBrg.setEnabled(false);
        btnCariBrg.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCariBrgActionPerformed(evt);
            }
        });
        pnAtas.add(btnCariBrg, new org.netbeans.lib.awtextra.AbsoluteConstraints(210, 60, -1, 20));

        jLabel9.setText("Harga");
        pnAtas.add(jLabel9, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 120, -1, -1));

        txtSlop.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtSlop.setText("0");
        txtSlop.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtSlopKeyReleased(evt);
            }
        });
        pnAtas.add(txtSlop, new org.netbeans.lib.awtextra.AbsoluteConstraints(210, 180, 40, -1));

        txtHarga.setEditable(false);
        txtHarga.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtHarga.setText("0");
        pnAtas.add(txtHarga, new org.netbeans.lib.awtextra.AbsoluteConstraints(180, 120, 100, -1));

        txtDiscPlgRp.setEditable(false);
        txtDiscPlgRp.setForeground(new java.awt.Color(0, 0, 204));
        txtDiscPlgRp.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtDiscPlgRp.setText("0");
        pnAtas.add(txtDiscPlgRp, new org.netbeans.lib.awtextra.AbsoluteConstraints(420, 30, 100, -1));

        txtDiscPlgPrs.setEditable(false);
        txtDiscPlgPrs.setForeground(new java.awt.Color(0, 0, 204));
        txtDiscPlgPrs.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtDiscPlgPrs.setText("0");
        pnAtas.add(txtDiscPlgPrs, new org.netbeans.lib.awtextra.AbsoluteConstraints(360, 30, 40, -1));

        jLabel10.setText("Discount Brg");
        pnAtas.add(jLabel10, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 144, -1, 20));

        btnCariPlg.setForeground(new java.awt.Color(0, 0, 204));
        btnCariPlg.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resource/search.png"))); // NOI18N
        btnCariPlg.setText("Cari");
        btnCariPlg.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCariPlgActionPerformed(evt);
            }
        });
        pnAtas.add(btnCariPlg, new org.netbeans.lib.awtextra.AbsoluteConstraints(580, 10, -1, 20));

        btnAdd.setText("Add");
        btnAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddActionPerformed(evt);
            }
        });
        pnAtas.add(btnAdd, new org.netbeans.lib.awtextra.AbsoluteConstraints(350, 200, 70, 30));

        txtBal.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtBal.setText("0");
        txtBal.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtBalKeyReleased(evt);
            }
        });
        pnAtas.add(txtBal, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 180, 40, -1));

        txtBks.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtBks.setText("0");
        txtBks.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtBksKeyReleased(evt);
            }
        });
        pnAtas.add(txtBks, new org.netbeans.lib.awtextra.AbsoluteConstraints(300, 180, 40, -1));

        jLabel13.setText("slop");
        pnAtas.add(jLabel13, new org.netbeans.lib.awtextra.AbsoluteConstraints(180, 180, -1, -1));

        jLabel14.setText("bks");
        pnAtas.add(jLabel14, new org.netbeans.lib.awtextra.AbsoluteConstraints(270, 180, -1, -1));

        jLabel15.setText("Jumlah");
        pnAtas.add(jLabel15, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 180, -1, -1));

        txtSubtotal.setEditable(false);
        txtSubtotal.setFont(new java.awt.Font("Tahoma", 1, 11));
        txtSubtotal.setForeground(new java.awt.Color(0, 153, 0));
        txtSubtotal.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtSubtotal.setText("0");
        txtSubtotal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtSubtotalActionPerformed(evt);
            }
        });
        pnAtas.add(txtSubtotal, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 210, 160, -1));

        jLabel16.setText("Subtotal");
        pnAtas.add(jLabel16, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 210, -1, -1));

        txtBalDB.setEditable(false);
        txtBalDB.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtBalDB.setText("0");
        pnAtas.add(txtBalDB, new org.netbeans.lib.awtextra.AbsoluteConstraints(380, 90, 30, -1));

        jLabel17.setText("bal");
        pnAtas.add(jLabel17, new org.netbeans.lib.awtextra.AbsoluteConstraints(350, 90, -1, -1));

        jLabel18.setText("slop");
        pnAtas.add(jLabel18, new org.netbeans.lib.awtextra.AbsoluteConstraints(420, 90, -1, -1));

        txtSlopDB.setEditable(false);
        txtSlopDB.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtSlopDB.setText("0");
        pnAtas.add(txtSlopDB, new org.netbeans.lib.awtextra.AbsoluteConstraints(450, 90, 30, -1));

        jLabel19.setText("bks");
        pnAtas.add(jLabel19, new org.netbeans.lib.awtextra.AbsoluteConstraints(490, 90, -1, -1));

        txtBksDB.setEditable(false);
        txtBksDB.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtBksDB.setText("0");
        pnAtas.add(txtBksDB, new org.netbeans.lib.awtextra.AbsoluteConstraints(520, 90, 30, -1));

        jLabel20.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resource/5.png"))); // NOI18N
        pnAtas.add(jLabel20, new org.netbeans.lib.awtextra.AbsoluteConstraints(460, 130, 130, 110));

        dcTglJual.setDateFormatString("dd/MM/yyyy");
        dcTglJual.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                dcTglJualPropertyChange(evt);
            }
        });
        pnAtas.add(dcTglJual, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 30, 140, -1));

        jLabel23.setText("Tanggal Jual");
        pnAtas.add(jLabel23, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 30, -1, -1));

        pnTengah.add(pnAtas, java.awt.BorderLayout.PAGE_START);

        pnShow.setLayout(new java.awt.CardLayout());

        pnTransaksi.setLayout(new java.awt.BorderLayout());

        tbTransaksi.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "Kode", "Nama Barang", "Harga (Rp)", "Jumlah", "Total(Rp)"
            }
        ));
        tbTransaksi.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
        tbTransaksi.setGridColor(new java.awt.Color(0, 153, 0));
        tbTransaksi.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                tbTransaksiMousePressed(evt);
            }
        });
        tbTransaksi.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tbTransaksiKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                tbTransaksiKeyReleased(evt);
            }
        });
        spTransaksi.setViewportView(tbTransaksi);

        pnTransaksi.add(spTransaksi, java.awt.BorderLayout.CENTER);

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
        jPanel1.setPreferredSize(new java.awt.Dimension(10, 140));
        jPanel1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jPanel1MousePressed(evt);
            }
        });
        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 10)); // NOI18N
        jLabel1.setText("Kembali");
        jPanel1.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(430, 110, 60, -1));

        txtHargaAkhir.setEditable(false);
        txtHargaAkhir.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        txtHargaAkhir.setForeground(new java.awt.Color(0, 0, 255));
        txtHargaAkhir.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtHargaAkhir.setText("0");
        jPanel1.add(txtHargaAkhir, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 20, 200, 40));

        txtHargaTotal.setEditable(false);
        txtHargaTotal.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        txtHargaTotal.setForeground(new java.awt.Color(0, 153, 0));
        txtHargaTotal.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtHargaTotal.setText("0");
        txtHargaTotal.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                txtHargaTotalMouseClicked(evt);
            }
        });
        txtHargaTotal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtHargaTotalActionPerformed(evt);
            }
        });
        txtHargaTotal.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtHargaTotalKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtHargaTotalKeyReleased(evt);
            }
        });
        jPanel1.add(txtHargaTotal, new org.netbeans.lib.awtextra.AbsoluteConstraints(500, 10, 140, -1));

        txtHargaDiscountBrg.setEditable(false);
        txtHargaDiscountBrg.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        txtHargaDiscountBrg.setForeground(new java.awt.Color(255, 0, 0));
        txtHargaDiscountBrg.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtHargaDiscountBrg.setText("0");
        jPanel1.add(txtHargaDiscountBrg, new org.netbeans.lib.awtextra.AbsoluteConstraints(500, 30, 140, -1));

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 10)); // NOI18N
        jLabel4.setText("Harga");
        jPanel1.add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(430, 10, 70, 20));

        jLabel11.setFont(new java.awt.Font("Tahoma", 1, 10));
        jLabel11.setText("Discount Brg");
        jPanel1.add(jLabel11, new org.netbeans.lib.awtextra.AbsoluteConstraints(430, 30, 90, 20));

        jLabel12.setFont(new java.awt.Font("Tahoma", 1, 10)); // NOI18N
        jLabel12.setText("Status");
        jPanel1.add(jLabel12, new org.netbeans.lib.awtextra.AbsoluteConstraints(190, 70, 60, -1));

        txtHargaDibayar.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        txtHargaDibayar.setForeground(new java.awt.Color(0, 153, 0));
        txtHargaDibayar.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtHargaDibayar.setText("0");
        txtHargaDibayar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                txtHargaDibayarMousePressed(evt);
            }
        });
        txtHargaDibayar.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                txtHargaDibayarFocusLost(evt);
            }
        });
        txtHargaDibayar.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtHargaDibayarKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtHargaDibayarKeyReleased(evt);
            }
        });
        jPanel1.add(txtHargaDibayar, new org.netbeans.lib.awtextra.AbsoluteConstraints(260, 110, 140, -1));

        txtHargaKembali.setEditable(false);
        txtHargaKembali.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        txtHargaKembali.setForeground(new java.awt.Color(0, 153, 0));
        txtHargaKembali.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtHargaKembali.setText("0");
        jPanel1.add(txtHargaKembali, new org.netbeans.lib.awtextra.AbsoluteConstraints(500, 110, 140, -1));

        btnTrOk.setText("Ok");
        btnTrOk.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnTrOkActionPerformed(evt);
            }
        });
        jPanel1.add(btnTrOk, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 110, 60, -1));

        btnTrCancel.setText("Cancel");
        btnTrCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnTrCancelActionPerformed(evt);
            }
        });
        jPanel1.add(btnTrCancel, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 110, 70, -1));

        btnTrNew.setText("New");
        btnTrNew.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnTrNewActionPerformed(evt);
            }
        });
        jPanel1.add(btnTrNew, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 80, 60, -1));

        lblSisa.setFont(new java.awt.Font("Tahoma", 1, 10)); // NOI18N
        lblSisa.setText("Sisa");
        jPanel1.add(lblSisa, new org.netbeans.lib.awtextra.AbsoluteConstraints(430, 90, 40, -1));

        txtHargaDiscountPlg.setEditable(false);
        txtHargaDiscountPlg.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        txtHargaDiscountPlg.setForeground(new java.awt.Color(255, 0, 0));
        txtHargaDiscountPlg.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtHargaDiscountPlg.setText("0");
        jPanel1.add(txtHargaDiscountPlg, new org.netbeans.lib.awtextra.AbsoluteConstraints(500, 70, 140, -1));

        jLabel22.setFont(new java.awt.Font("Tahoma", 1, 10)); // NOI18N
        jLabel22.setText("Harga");
        jPanel1.add(jLabel22, new org.netbeans.lib.awtextra.AbsoluteConstraints(430, 50, 70, 20));

        txtHargaTotal2.setEditable(false);
        txtHargaTotal2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        txtHargaTotal2.setForeground(new java.awt.Color(0, 153, 0));
        txtHargaTotal2.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtHargaTotal2.setText("0");
        txtHargaTotal2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                txtHargaTotal2MouseClicked(evt);
            }
        });
        txtHargaTotal2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtHargaTotal2ActionPerformed(evt);
            }
        });
        txtHargaTotal2.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtHargaTotal2KeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtHargaTotal2KeyReleased(evt);
            }
        });
        jPanel1.add(txtHargaTotal2, new org.netbeans.lib.awtextra.AbsoluteConstraints(500, 50, 140, -1));

        jLabel24.setFont(new java.awt.Font("Tahoma", 1, 10)); // NOI18N
        jLabel24.setText("Discount Plg");
        jPanel1.add(jLabel24, new org.netbeans.lib.awtextra.AbsoluteConstraints(430, 70, 90, -1));

        txtSisaBayar.setEditable(false);
        txtSisaBayar.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        txtSisaBayar.setForeground(new java.awt.Color(0, 153, 0));
        txtSisaBayar.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtSisaBayar.setText("0");
        txtSisaBayar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                txtSisaBayarMousePressed(evt);
            }
        });
        txtSisaBayar.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                txtSisaBayarFocusLost(evt);
            }
        });
        txtSisaBayar.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtSisaBayarKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtSisaBayarKeyReleased(evt);
            }
        });
        jPanel1.add(txtSisaBayar, new org.netbeans.lib.awtextra.AbsoluteConstraints(500, 90, 140, -1));

        cbStatusBayar.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Tunai", "Kredit" }));
        cbStatusBayar.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cbStatusBayarItemStateChanged(evt);
            }
        });
        jPanel1.add(cbStatusBayar, new org.netbeans.lib.awtextra.AbsoluteConstraints(260, 70, 80, -1));

        jLabel25.setFont(new java.awt.Font("Tahoma", 1, 10)); // NOI18N
        jLabel25.setText("Dibayar");
        jPanel1.add(jLabel25, new org.netbeans.lib.awtextra.AbsoluteConstraints(190, 110, 60, -1));

        txtUangMuka.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        txtUangMuka.setForeground(new java.awt.Color(0, 153, 0));
        txtUangMuka.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtUangMuka.setText("0");
        txtUangMuka.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                txtUangMukaMousePressed(evt);
            }
        });
        txtUangMuka.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                txtUangMukaFocusLost(evt);
            }
        });
        txtUangMuka.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtUangMukaKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtUangMukaKeyReleased(evt);
            }
        });
        jPanel1.add(txtUangMuka, new org.netbeans.lib.awtextra.AbsoluteConstraints(260, 90, 140, -1));

        lblUangMuka.setFont(new java.awt.Font("Tahoma", 1, 10)); // NOI18N
        lblUangMuka.setText("Uang Muka");
        jPanel1.add(lblUangMuka, new org.netbeans.lib.awtextra.AbsoluteConstraints(190, 90, 60, -1));

        pnTransaksi.add(jPanel1, java.awt.BorderLayout.PAGE_END);

        pnShow.add(pnTransaksi, "transaksi");

        pnBarang.setLayout(new java.awt.BorderLayout());

        pnCrBrg.setBackground(new java.awt.Color(255, 255, 255));
        pnCrBrg.setLayout(new java.awt.BorderLayout());

        tbBarang.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tbBarang.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                tbBarangMousePressed(evt);
            }
        });
        tbBarang.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tbBarangKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                tbBarangKeyReleased(evt);
            }
        });
        spBarang.setViewportView(tbBarang);

        pnCrBrg.add(spBarang, java.awt.BorderLayout.CENTER);

        pnAtas1.setBackground(new java.awt.Color(255, 255, 255));
        pnAtas1.setPreferredSize(new java.awt.Dimension(410, 70));
        pnAtas1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        btnShowAllBrg.setText("Show All");
        btnShowAllBrg.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnShowAllBrgActionPerformed(evt);
            }
        });
        pnAtas1.add(btnShowAllBrg, new org.netbeans.lib.awtextra.AbsoluteConstraints(340, 40, 80, -1));
        pnAtas1.add(txtNmSrcBrg, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 40, 270, -1));

        cbSrcBrg.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Kode Brg", "Nama Brg" }));
        pnAtas1.add(cbSrcBrg, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 10, 70, -1));

        btnSearchBrg.setText("Search");
        btnSearchBrg.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSearchBrgActionPerformed(evt);
            }
        });
        pnAtas1.add(btnSearchBrg, new org.netbeans.lib.awtextra.AbsoluteConstraints(340, 10, 80, -1));

        lblCloseBrg.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resource/Delete.png"))); // NOI18N
        lblCloseBrg.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lblCloseBrgMouseClicked(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                lblCloseBrgMouseReleased(evt);
            }
        });
        pnAtas1.add(lblCloseBrg, new org.netbeans.lib.awtextra.AbsoluteConstraints(570, 10, 40, 40));

        infoBrg.setFont(new java.awt.Font("Tahoma", 1, 14));
        infoBrg.setForeground(new java.awt.Color(0, 0, 204));
        infoBrg.setText("Data Barang");
        pnAtas1.add(infoBrg, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 10, -1, -1));

        pnCrBrg.add(pnAtas1, java.awt.BorderLayout.PAGE_START);

        pnBarang.add(pnCrBrg, java.awt.BorderLayout.CENTER);

        pnShow.add(pnBarang, "barang");

        pnPelanggan.setLayout(new java.awt.BorderLayout());

        pnCrPlg.setBackground(new java.awt.Color(255, 255, 255));
        pnCrPlg.setLayout(new java.awt.BorderLayout());

        tbPlg.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tbPlg.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                tbPlgMousePressed(evt);
            }
        });
        tbPlg.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tbPlgKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                tbPlgKeyReleased(evt);
            }
        });
        spPlg.setViewportView(tbPlg);

        pnCrPlg.add(spPlg, java.awt.BorderLayout.CENTER);

        pnAtas2.setBackground(new java.awt.Color(255, 255, 255));
        pnAtas2.setPreferredSize(new java.awt.Dimension(410, 70));
        pnAtas2.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        btnShowAllPlg.setText("Show All");
        btnShowAllPlg.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnShowAllPlgActionPerformed(evt);
            }
        });
        pnAtas2.add(btnShowAllPlg, new org.netbeans.lib.awtextra.AbsoluteConstraints(340, 40, 80, -1));
        pnAtas2.add(txtNmSrcPlg, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 40, 270, -1));

        cbSrcPlg.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Kode Plg", "Nama Plg" }));
        pnAtas2.add(cbSrcPlg, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 20, 80, -1));

        btnSearchPlg.setText("Search");
        btnSearchPlg.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSearchPlgActionPerformed(evt);
            }
        });
        pnAtas2.add(btnSearchPlg, new org.netbeans.lib.awtextra.AbsoluteConstraints(340, 10, 80, -1));

        lblClosePlg.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resource/Delete.png"))); // NOI18N
        lblClosePlg.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lblClosePlgMouseClicked(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                lblClosePlgMouseReleased(evt);
            }
        });
        pnAtas2.add(lblClosePlg, new org.netbeans.lib.awtextra.AbsoluteConstraints(570, 10, 40, 40));

        infoPlg.setFont(new java.awt.Font("Tahoma", 1, 14));
        infoPlg.setText("Data Pelanggan");
        pnAtas2.add(infoPlg, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 10, -1, -1));

        pnCrPlg.add(pnAtas2, java.awt.BorderLayout.PAGE_START);

        pnPelanggan.add(pnCrPlg, java.awt.BorderLayout.CENTER);

        pnShow.add(pnPelanggan, "pelanggan");

        pnDBarang.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        infoDBrg.setFont(new java.awt.Font("Tahoma", 1, 14));
        infoDBrg.setText("Discount Barang");
        pnDBarang.add(infoDBrg, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 10, -1, -1));

        pnShow.add(pnDBarang, "discbarang");

        pnDPlg.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        infoDPlg.setFont(new java.awt.Font("Tahoma", 1, 14));
        infoDPlg.setText("Discount Pelanggan");
        pnDPlg.add(infoDPlg, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 10, -1, -1));

        pnShow.add(pnDPlg, "discpelanggan");

        pnTengah.add(pnShow, java.awt.BorderLayout.CENTER);

        getContentPane().add(pnTengah, java.awt.BorderLayout.CENTER);

        setBounds(0, 0, 675, 495);
    }// </editor-fold>//GEN-END:initComponents

    private void formInternalFrameClosing(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formInternalFrameClosing
        // TODO add your handling code here:
        int clossing;
        clossing = JOptionPane.showConfirmDialog(this,
                "Tutup Transaksi Penjualan?",
                "Konfirmasi",
                JOptionPane.YES_NO_OPTION);
        if (clossing == 0){
            this.dispose();
            FormMain.isftPen = false;
        }
    }//GEN-LAST:event_formInternalFrameClosing

    private void tbTransaksiMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tbTransaksiMousePressed
        //getDataFromBarang();
}//GEN-LAST:event_tbTransaksiMousePressed

    private void tbTransaksiKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tbTransaksiKeyPressed
        // TODO add your handling code here:
}//GEN-LAST:event_tbTransaksiKeyPressed

    private void tbTransaksiKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tbTransaksiKeyReleased
        // TODO add your handling code here:
        //getDataFromBarang();
        
}//GEN-LAST:event_tbTransaksiKeyReleased

    private void txtKdBrgKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtKdBrgKeyReleased
        // TODO add your handling code here:
        txtKdBrg.setText(txtKdBrg.getText().toUpperCase());
}//GEN-LAST:event_txtKdBrgKeyReleased

    private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddActionPerformed
        // TODO add your handling code here:
        addData();
}//GEN-LAST:event_btnAddActionPerformed

    private void btnCariBrgActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCariBrgActionPerformed
        CardLayout cl = (CardLayout)(pnShow.getLayout());
        cl.show(pnShow, "barang");
        tampilSearchBrg();
    }//GEN-LAST:event_btnCariBrgActionPerformed

    private void tbBarangMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tbBarangMousePressed
        getDataFromBarang();
}//GEN-LAST:event_tbBarangMousePressed

    private void tbBarangKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tbBarangKeyPressed
        // TODO add your handling code here:
        getDataFromBarang();
}//GEN-LAST:event_tbBarangKeyPressed

    private void tbBarangKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tbBarangKeyReleased
        // TODO add your handling code here:
        getDataFromBarang();
}//GEN-LAST:event_tbBarangKeyReleased

    private void btnShowAllBrgActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnShowAllBrgActionPerformed
        // TODO add your handling code here:
        tampilAllBrg();
}//GEN-LAST:event_btnShowAllBrgActionPerformed

    private void btnSearchBrgActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSearchBrgActionPerformed
        // TODO add your handling code here:
        tampilSearchBrg();
}//GEN-LAST:event_btnSearchBrgActionPerformed

    private void lblCloseBrgMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblCloseBrgMouseClicked
        // TODO add your handling code here:
        CardLayout cl = (CardLayout)(pnShow.getLayout());
        cl.show(pnShow, "transaksi");
    }//GEN-LAST:event_lblCloseBrgMouseClicked

    private void lblCloseBrgMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblCloseBrgMouseReleased
        // TODO add your handling code here:
        CardLayout cl = (CardLayout)(pnShow.getLayout());
        cl.show(pnShow, "transaksi");
    }//GEN-LAST:event_lblCloseBrgMouseReleased

    private void tbPlgMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tbPlgMousePressed
        // TODO add your handling code here:
        getDataFromPlg();
    }//GEN-LAST:event_tbPlgMousePressed

    private void tbPlgKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tbPlgKeyPressed
        // TODO add your handling code here:
        getDataFromPlg();
    }//GEN-LAST:event_tbPlgKeyPressed

    private void tbPlgKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tbPlgKeyReleased
        // TODO add your handling code here:
        getDataFromPlg();
    }//GEN-LAST:event_tbPlgKeyReleased

    private void btnShowAllPlgActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnShowAllPlgActionPerformed
        // TODO add your handling code here:
        tampilAllPlg();
    }//GEN-LAST:event_btnShowAllPlgActionPerformed

    private void btnSearchPlgActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSearchPlgActionPerformed
        // TODO add your handling code here:
        tampilSearchPlg();
    }//GEN-LAST:event_btnSearchPlgActionPerformed

    private void lblClosePlgMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblClosePlgMouseClicked
        // TODO add your handling code here:
        CardLayout cl = (CardLayout)(pnShow.getLayout());
        cl.show(pnShow, "transaksi");
    }//GEN-LAST:event_lblClosePlgMouseClicked

    private void lblClosePlgMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblClosePlgMouseReleased
        // TODO add your handling code here:
        CardLayout cl = (CardLayout)(pnShow.getLayout());
        cl.show(pnShow, "transaksi");
    }//GEN-LAST:event_lblClosePlgMouseReleased

    private void btnCariPlgActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCariPlgActionPerformed
        // TODO add your handling code here:
        CardLayout cl = (CardLayout)(pnShow.getLayout());
        cl.show(pnShow, "pelanggan");
        tampilAllPlg();
    }//GEN-LAST:event_btnCariPlgActionPerformed

    private void cbTipeHargaItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cbTipeHargaItemStateChanged
        // TODO add your handling code here:
        setHarga();
    }//GEN-LAST:event_cbTipeHargaItemStateChanged

    private void btnTrOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnTrOkActionPerformed
        // TODO add your handling code here:
        if(iHAkhir == 0){
            JOptionPane.showMessageDialog(this, "Data harus diisi!","Error",
                    JOptionPane.ERROR_MESSAGE);
        }else{
            if(iHDibayar < iHAkhir){
                JOptionPane.showMessageDialog(this, "Uang dibayar kurang!","Error",
                    JOptionPane.ERROR_MESSAGE);
            }else{
                int yakin;
                yakin = JOptionPane.showConfirmDialog(this,
                        "Apakah Anda yakin?",
                        "Konfirmasi",
                        JOptionPane.YES_NO_OPTION);
                if (yakin == 0){
                    insertDataJual();
                    insertDataJualDetail();
                }
            }
        }
    }//GEN-LAST:event_btnTrOkActionPerformed

    private void txtHargaTotalKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtHargaTotalKeyReleased
        // TODO add your handling code here:
    }//GEN-LAST:event_txtHargaTotalKeyReleased

    private void txtHargaTotalKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtHargaTotalKeyPressed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtHargaTotalKeyPressed

    private void txtHargaTotalMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_txtHargaTotalMouseClicked
        // TODO add your handling code here:
        //java.text.DecimalFormat nft = new java.text.DecimalFormat("#000.###");
        //nft.setDecimalSeparatorAlwaysShown(false);
        //txtHargaTotal.setText(kdGol + "." + nft.format(x))
        //txtHargaTotal.setText(txtHargaTotal.(se)))
    }//GEN-LAST:event_txtHargaTotalMouseClicked

    private void txtHargaDibayarKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtHargaDibayarKeyPressed
        // TODO add your handling code here:
        
    }//GEN-LAST:event_txtHargaDibayarKeyPressed

    private void txtHargaDibayarFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtHargaDibayarFocusLost
        // TODO add your handling code here:
        txtHargaDibayar.setText(toRp(iHDibayar));
    }//GEN-LAST:event_txtHargaDibayarFocusLost

    private void txtHargaTotalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtHargaTotalActionPerformed
        // TODO add your handling code here:
        
    }//GEN-LAST:event_txtHargaTotalActionPerformed

    private void btnTrNewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnTrNewActionPerformed
        // TODO add your handling code here:
        int clossing;
        clossing = JOptionPane.showConfirmDialog(this,
                "Buat Transaksi baru?",
                "Konfirmasi",
                JOptionPane.YES_NO_OPTION);
        if (clossing == 0){
            kosongkanNew();
        }
        
    }//GEN-LAST:event_btnTrNewActionPerformed

    private void btnTrCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnTrCancelActionPerformed
        // TODO add your handling code here:
        int clossing;
        clossing = JOptionPane.showConfirmDialog(this,
                "Batalkan Transaksi Penjualan?",
                "Konfirmasi",
                JOptionPane.YES_NO_OPTION);
        if (clossing == 0){
            this.dispose();
            FormMain.isftPen = false;
        }
    }//GEN-LAST:event_btnTrCancelActionPerformed

    private void txtHargaDibayarKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtHargaDibayarKeyReleased
        // TODO add your handling code here:
        hitungKembali();
        //txtHargaDibayar.setText(iHDibayar.toString());
    }//GEN-LAST:event_txtHargaDibayarKeyReleased

    private void txtSubtotalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtSubtotalActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_txtSubtotalActionPerformed

    private void txtHargaDibayarMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_txtHargaDibayarMousePressed
        // TODO add your handling code here:
        txtHargaDibayar.setText(iHDibayar.toString());
    }//GEN-LAST:event_txtHargaDibayarMousePressed

    private void txtHargaTotal2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_txtHargaTotal2MouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_txtHargaTotal2MouseClicked

    private void txtHargaTotal2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtHargaTotal2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtHargaTotal2ActionPerformed

    private void txtHargaTotal2KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtHargaTotal2KeyPressed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtHargaTotal2KeyPressed

    private void txtHargaTotal2KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtHargaTotal2KeyReleased
        // TODO add your handling code here:
    }//GEN-LAST:event_txtHargaTotal2KeyReleased

    private void dcTglJualPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_dcTglJualPropertyChange
        // TODO add your handling code here:
        if(dcTglJual.getDate()!=null){
            //format yyyy-MM-dd utk mysql
            SimpleDateFormat formatTgl = new SimpleDateFormat("yyyy-MM-dd");
            sTglJual= formatTgl.format(dcTglJual.getDate());
        }
}//GEN-LAST:event_dcTglJualPropertyChange

    private void txtSisaBayarMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_txtSisaBayarMousePressed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtSisaBayarMousePressed

    private void txtSisaBayarFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtSisaBayarFocusLost
        // TODO add your handling code here:
    }//GEN-LAST:event_txtSisaBayarFocusLost

    private void txtSisaBayarKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtSisaBayarKeyPressed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtSisaBayarKeyPressed

    private void txtSisaBayarKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtSisaBayarKeyReleased
        // TODO add your handling code here:
    }//GEN-LAST:event_txtSisaBayarKeyReleased

    private void txtUangMukaMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_txtUangMukaMousePressed
        // TODO add your handling code here:
        txtUangMuka.setText(iUangMuka.toString());
    }//GEN-LAST:event_txtUangMukaMousePressed

    private void txtUangMukaFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtUangMukaFocusLost
        // TODO add your handling code here:
        txtUangMuka.setText(toRp(iUangMuka));
    }//GEN-LAST:event_txtUangMukaFocusLost

    private void txtUangMukaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtUangMukaKeyPressed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtUangMukaKeyPressed

    private void txtUangMukaKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtUangMukaKeyReleased
        // TODO add your handling code here:
        hitungSisaBayar();        
        //txtUangMuka.setText(iUangMuka.toString());
    }//GEN-LAST:event_txtUangMukaKeyReleased

    private void cbStatusBayarItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cbStatusBayarItemStateChanged
        // TODO add your handling code here:
        if(cbStatusBayar.getSelectedItem().toString().equals("Kredit")){
            lblUangMuka.setVisible(true);            
            iUangMuka = 0;
            txtUangMuka.setText(toRp(iUangMuka));
            txtUangMuka.setVisible(true);
            lblSisa.setVisible(true);
            iSisaBayar = 0;
            txtSisaBayar.setText(toRp(iSisaBayar));
            txtSisaBayar.setVisible(true);
        }else{
            lblUangMuka.setVisible(false);
            txtUangMuka.setVisible(false);
            lblSisa.setVisible(false);
            txtSisaBayar.setVisible(false);
        }
    }//GEN-LAST:event_cbStatusBayarItemStateChanged

    private void txtBksKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtBksKeyReleased
        // TODO add your handling code here:
        hitungTxtSubTotal();
    }//GEN-LAST:event_txtBksKeyReleased

    private void txtSlopKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtSlopKeyReleased
        // TODO add your handling code here:
        hitungTxtSubTotal();
    }//GEN-LAST:event_txtSlopKeyReleased

    private void txtBalKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtBalKeyReleased
        // TODO add your handling code here:
        hitungTxtSubTotal();
    }//GEN-LAST:event_txtBalKeyReleased

    private void jPanel1MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jPanel1MousePressed
        // TODO add your handling code here:
        //System.out.println("clicked");
        //hitungSisaBayar();
        //hitungKembali();
        //txtHargaDibayar.setText(toRp(iHDibayar));
        //txtUangMuka.setText(toRp(iUangMuka));

    }//GEN-LAST:event_jPanel1MousePressed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAdd;
    private javax.swing.JButton btnCariBrg;
    private javax.swing.JButton btnCariPlg;
    private javax.swing.JButton btnSearchBrg;
    private javax.swing.JButton btnSearchPlg;
    private javax.swing.JButton btnShowAllBrg;
    private javax.swing.JButton btnShowAllPlg;
    private javax.swing.JButton btnTrCancel;
    private javax.swing.JButton btnTrNew;
    private javax.swing.JButton btnTrOk;
    private javax.swing.JComboBox cbSrcBrg;
    private javax.swing.JComboBox cbSrcPlg;
    private javax.swing.JComboBox cbStatusBayar;
    private javax.swing.JComboBox cbTipeHarga;
    private com.toedter.calendar.JDateChooser dcTglJual;
    private javax.swing.JLabel infoBrg;
    private javax.swing.JLabel infoDBrg;
    private javax.swing.JLabel infoDPlg;
    private javax.swing.JLabel infoPlg;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JLabel lblCloseBrg;
    private javax.swing.JLabel lblClosePlg;
    private javax.swing.JLabel lblSisa;
    private javax.swing.JLabel lblUangMuka;
    private javax.swing.JPanel pnAtas;
    private javax.swing.JPanel pnAtas1;
    private javax.swing.JPanel pnAtas2;
    private javax.swing.JPanel pnBarang;
    private javax.swing.JPanel pnCrBrg;
    private javax.swing.JPanel pnCrPlg;
    private javax.swing.JPanel pnDBarang;
    private javax.swing.JPanel pnDPlg;
    private javax.swing.JPanel pnPelanggan;
    private javax.swing.JPanel pnShow;
    private javax.swing.JPanel pnTengah;
    private javax.swing.JPanel pnTransaksi;
    private javax.swing.JScrollPane spBarang;
    private javax.swing.JScrollPane spPlg;
    private javax.swing.JScrollPane spTransaksi;
    private javax.swing.JTable tbBarang;
    private javax.swing.JTable tbPlg;
    private javax.swing.JTable tbTransaksi;
    private javax.swing.JTextField txtBal;
    private javax.swing.JTextField txtBalDB;
    private javax.swing.JTextField txtBks;
    private javax.swing.JTextField txtBksDB;
    private javax.swing.JTextField txtDiscBrgPrs;
    private javax.swing.JTextField txtDiscBrgRp;
    private javax.swing.JTextField txtDiscPlgPrs;
    private javax.swing.JTextField txtDiscPlgRp;
    private javax.swing.JTextField txtHarga;
    private javax.swing.JTextField txtHargaAkhir;
    private javax.swing.JTextField txtHargaDibayar;
    private javax.swing.JTextField txtHargaDiscountBrg;
    private javax.swing.JTextField txtHargaDiscountPlg;
    private javax.swing.JTextField txtHargaKembali;
    private javax.swing.JTextField txtHargaTotal;
    private javax.swing.JTextField txtHargaTotal2;
    private javax.swing.JTextField txtKdBrg;
    private javax.swing.JTextField txtKdJual;
    private javax.swing.JTextField txtKdPlg;
    private javax.swing.JTextField txtNamaBrg;
    private javax.swing.JTextField txtNamaPlg;
    private javax.swing.JTextField txtNmSrcBrg;
    private javax.swing.JTextField txtNmSrcPlg;
    private javax.swing.JTextField txtSisaBayar;
    private javax.swing.JTextField txtSlop;
    private javax.swing.JTextField txtSlopDB;
    private javax.swing.JTextField txtSubtotal;
    private javax.swing.JTextField txtUangMuka;
    // End of variables declaration//GEN-END:variables

    private void kosongkan(){
        //txtKdBrg.requestFocus();
        
        txtHarga.setText("");
        
        txtKdBrg.setText("");
        txtNamaBrg.setText("");
        txtDiscBrgPrs.setText("0");
        txtDiscBrgRp.setText("0");

        txtBal.setText("0");
        txtSlop.setText("0");
        txtBks.setText("0");

        txtSubtotal.setText(toRp(0));
    }
    
    private void kosongkanNew(){        
        txtKdJual.setText("");
        setKdJual();        
        
        /* barang */
        txtKdBrg.setText("");
        txtNamaBrg.setText("");
        txtDiscBrgPrs.setText("0");
        txtDiscBrgRp.setText("0");
        txtHarga.setText("");

        /* stok */
        txtBal.setText("0");
        txtSlop.setText("0");
        txtBks.setText("0");
        txtBalDB.setText("0");
        txtSlopDB.setText("0");
        txtBksDB.setText("0");

        /* pelanggan */
        txtKdPlg.setText("");
        txtDiscPlgPrs.setText("0");
        txtNamaPlg.setText("");
        txtDiscPlgRp.setText("0");

        /* to RP inialization */
        iHTotal = 0;
        iHDiskonBrg = 0;
        iHTotal2 = 0;
        iHDiskonPlg = 0;
        iHAkhir = 0;
        iHDibayar = 0;
        iHKembali = 0;
        iUangMuka = 0;
        iSisaBayar = 0;

        txtSubtotal.setText(toRp(0));
        txtHargaTotal.setText(toRp(iHTotal));
        txtHargaDiscountBrg.setText(toRp(iHDiskonBrg));
        txtHargaTotal2.setText(toRp(iHTotal2));
        txtHargaDiscountPlg.setText(toRp(iHDiskonPlg));
        txtHargaAkhir.setText(toRp(iHAkhir));
        txtHargaDibayar.setText(toRp(iHDibayar));
        txtHargaKembali.setText(toRp(iHKembali));
        txtUangMuka.setText(toRp(iUangMuka));
        txtSisaBayar.setText(toRp(iSisaBayar));
        

        /* tombol2 */
        //btnTrOk.setEnabled(false);        
        btnCariBrg.setEnabled(false);        
        
        //tbTransaksi.removeAll();
        DftTabModeTr.setNumRows(0);  
        /*
        int rows = tbTransaksi.getRowCount();
        for (int i=0; i< rows; i++) {
            //tbTransaksi..removeRow(0);
            //tbTransaksi.removeRowSelectionInterval(i, i);
            DftTabModeTr.removeRow(i);
            //tbTransaksi.removeRow(i);
        }
         * 
         */
       
    }   

    private void tampilSearchBrg(){
        /*
        String[] columnNames =
        {"No","Kode","Kota"};

        table = new  JTable(
                getDataSearch(), columnNames);
        spKota.setViewportView(table);
        */
        String srcby = "";
        if(cbSrcBrg.getSelectedItem().toString().equals("Kode Brg")){
            srcby = "kdBrg";
        }else{
            srcby = "nmBrg";
        }

        Object[] Baris={"No","Kode","Nama"};
        DftTabModeBrg=new DefaultTableModel(null,Baris);
        tbBarang.setModel(DftTabModeBrg);

        try {
            java.sql.Statement stmt = conn.createStatement();
            java.sql.ResultSet rslt = stmt.executeQuery(
                    "SELECT * FROM tbrg WHERE UPPER(" + srcby +
                    ") like UPPER('%" +
                    txtNmSrcBrg.getText() + "%')");
            //int iNo = 0;
            while (rslt.next()) {
                int row = rslt.getRow();
                String sKdBrg = rslt.getString("kdBrg");
                String sNmBrg = rslt.getString("nmBrg");
                //String sNamaKota = rslt.getString("ket");

                String[] dataField = {Integer.toString(row), sKdBrg, sNmBrg};
                DftTabModeBrg.addRow(dataField);
            }

        }
        catch(SQLException e) {
            System.out.println("gagal : " + e.toString());
        }
    }
    private void tampilSearchPlg(){
        String srcby = "";
        if(cbSrcBrg.getSelectedItem().toString().equals("Kode Plg")){
            srcby = "kdPlg";
        }else{
            srcby = "nmPlg";
        }

        Object[] Baris={"No","Kode","Nama"};
        DftTabModePlg=new DefaultTableModel(null,Baris);
        tbPlg.setModel(DftTabModePlg);

        try {
            java.sql.Statement stmt = conn.createStatement();
            java.sql.ResultSet rslt = stmt.executeQuery(
                    "SELECT * FROM tplg WHERE UPPER(" + srcby +
                    ") like UPPER('%" +
                    txtNmSrcPlg.getText() + "%')");
            //int iNo = 0;
            while (rslt.next()) {
                int row = rslt.getRow();
                String sKdPlg = rslt.getString("kdPlg");
                String sNmPlg = rslt.getString("nmPlg");
                //String sNamaKota = rslt.getString("ket");

                String[] dataField = {Integer.toString(row), sKdPlg, sNmPlg};
                DftTabModePlg.addRow(dataField);
            }

        }
        catch(SQLException e) {
            System.out.println("gagal : " + e.toString());
        }
    }
    private void tampilAllBrg(){

        String srcby = "";
        txtNmSrcBrg.setText("");

        Object[] Baris={"No","Kode","Nama"};
        DftTabModeBrg=new DefaultTableModel(null,Baris);
        tbBarang.setModel(DftTabModeBrg);

        try {
            java.sql.Statement stmt = conn.createStatement();
            java.sql.ResultSet rslt = stmt.executeQuery(
                    "SELECT * FROM tbrg");
            //int iNo = 0;
            while (rslt.next()) {
                int row = rslt.getRow();
                String sKdBrg = rslt.getString("kdBrg");
                String sNamaBrg = rslt.getString("nmBrg");

                String[] dataField = {Integer.toString(row), sKdBrg, sNamaBrg};
                DftTabModeBrg.addRow(dataField);
            }          

        }
        catch(SQLException e) {
            System.out.println("gagal : " + e.toString());
        }
        // Disable auto resizing
        //tbBarang.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

        // Set the first visible column to 100 pixels wide
        //int vColIndex = 0;
        //TableColumn col = tbBarang.getColumnModel().getColumn(vColIndex);
        //int width = 50;
        //col.setPreferredWidth(width);
    }    
    private void tampilAllPlg(){
        String srcby = "";
        txtNmSrcPlg.setText("");

        Object[] Baris={"No","Kode","Nama"};
        DftTabModePlg=new DefaultTableModel(null,Baris);
        tbPlg.setModel(DftTabModePlg);

        try {
            java.sql.Statement stmt = conn.createStatement();
            java.sql.ResultSet rslt = stmt.executeQuery(
                    "SELECT * FROM tplg");
            //int iNo = 0;
            while (rslt.next()) {
                int row = rslt.getRow();
                String sKdPlg = rslt.getString("kdPlg");
                String sNamaPlg = rslt.getString("nmPlg");

                String[] dataField = {Integer.toString(row), sKdPlg, sNamaPlg};
                DftTabModePlg.addRow(dataField);
            }

        }
        catch(SQLException e) {
            System.out.println("gagal : " + e.toString());
        }        
    }
    
    private void deleteData(){
            try {
                int deleting;
                deleting = JOptionPane.showConfirmDialog(this,
                        "Apakah Anda yakin akan menghapus "

                        //+ cbKodeKota.getSelectedItem().toString() +" "
                        +txtKdBrg.getText() +"?",
                        "Konfirmasi",
                        JOptionPane.YES_NO_OPTION);
                if (deleting == 0){

                    PreparedStatement pStatement = null;
                    String sql = "DELETE FROM tbrg_gol " +
                            "WHERE kdGol=? ";
                    pStatement = conn.prepareStatement(sql);

                    pStatement.setString(1, txtKdBrg.getText());

                    int intTambah = pStatement.executeUpdate();
                    if (intTambah >0){
                        JOptionPane.showMessageDialog(this,
                                "Delete sukses", "Informasi",
                                JOptionPane.INFORMATION_MESSAGE);

                    }else {
                        JOptionPane.showMessageDialog(this,
                                "Delete gagal", "Informasi",
                                JOptionPane.INFORMATION_MESSAGE);
                    }

                    pStatement.close();

                    kosongkan();
                    //kd/tampilData();
                }
            } catch(SQLException e){
                System.out.println("koneksi gagal " + e.toString());
            }
    }
    private boolean isDuplicatePKey(){
        //Object oKdGol, oNamaGol;//, oKet;//, oTest;
        String pKey = txtKdBrg.getText();
        boolean result = true;
        int row = 0;

        try {
            java.sql.Statement stmt = conn.createStatement();
            java.sql.ResultSet rslt = stmt.executeQuery("Select * from tbrg_gol WHERE kdGol=" +
                    "'" +pKey+ "'");
            while (rslt.next()) {
                row = rslt.getRow();
            }
                if(row > 0){
                    JOptionPane.showMessageDialog(this, "Kode "+pKey+" sudah ada"
                            ,"Peringatan",JOptionPane.WARNING_MESSAGE);
                    result = true;
                }else{
                    result = false;
                }
            System.out.println("row : " + row);
        }
        catch(SQLException e) {
            System.out.println("gagal : " + e.toString());
        }
        return result;
    }
    private void insertDataJual(){        
        java.sql.PreparedStatement pStatement = null;
        String sql = "INSERT INTO tjual " +
                "(idJual, tgl_jual, kdPlg, kdTipeHarga, " +
                "htotal1, hdiscbrg, htotal2, hdiscplg, " +
                "hdibayar, hkembali, total_harga, " +
                "uang_muka, sisa, " +
                "user_id) " +
                "VALUES (?,?,?,?, ?,?,?,?, ?,?,?,?,?, ?)";
        try {
            pStatement = conn.prepareStatement(sql);
            pStatement.setString(1, txtKdJual.getText());
            pStatement.setString(2, sTglJual);            
            pStatement.setString(3, txtKdPlg.getText());
            String kdTipe = Integer.toString(cbTipeHarga.getSelectedIndex());
            pStatement.setString(4, kdTipe);

            pStatement.setInt(5, iHTotal);
            pStatement.setInt(6, iHDiskonBrg);
            pStatement.setInt(7, iHTotal2);
            pStatement.setInt(8, iHDiskonPlg);
            
            pStatement.setInt(9, iHDibayar);
            pStatement.setInt(10, iHKembali);
            pStatement.setInt(11, iHAkhir);
            pStatement.setInt(12, iUangMuka);
            pStatement.setInt(13, iSisaBayar);
            
            pStatement.setString(14, "admin");

            int intTambah = pStatement.executeUpdate();
            if (intTambah>0){
                //JOptionPane.showMessageDialog(this,
                //        "Penambahan sukses", "Informasi",
                //        JOptionPane.INFORMATION_MESSAGE);
            }else{
                JOptionPane.showMessageDialog(this,
                        "Penambahan gagal", "Informasi",
                        JOptionPane.INFORMATION_MESSAGE);
            }
            pStatement.close();
        }
        catch(SQLException e){
            System.out.println("koneksi gagal " + e.toString());
        }
        
    }
    private void insertDataJualDetail(){
        // panggil method koneksi
        //java.sql.Connection conn = new DBConnection().connect();
        
        java.sql.PreparedStatement pStatement = null;
        String sql = "INSERT INTO tjual_detail " +
                "(idJual, kdBrg, hargaJual, kdTipeHarga, bal, slop, bks, subtotal) " +
                "VALUES (?,?,?,?,?,?,?,?)";
                  
        int rows = tbTransaksi.getRowCount();
        for (int i=0; i< rows; i++) {
            try {
                pStatement = conn.prepareStatement(sql);
                //iHarga = iHarga + Integer.parseInt(tbTransaksi.getValueAt(i, 5).toString());
                pStatement.setString(1, txtKdJual.getText());
                pStatement.setString(2, tbTransaksi.getValueAt(i, 1).toString());//kdbrg
                pStatement.setString(3, tbTransaksi.getValueAt(i, 3).toString());//harga

                String kdTipe = Integer.toString(cbTipeHarga.getSelectedIndex());
                pStatement.setString(4, kdTipe);//tipeharga

                //"0No","1Kode","2Namabrg","3Harga(Rp)","4Bal","5Slop","6Bks","7Total(Rp)"
                //Object[] Baris={"No","1Kode","2Nama Barang","3Harga (Rp)","4Jumlah","5Total(Rp)"};
                
                //bal
                pStatement.setString(5, tbTransaksi.getValueAt(i, 4).toString());
                //slop
                pStatement.setString(6, tbTransaksi.getValueAt(i, 5).toString());
                //bks
                pStatement.setString(7, tbTransaksi.getValueAt(i, 6).toString());
                //subtotal
                pStatement.setString(8, tbTransaksi.getValueAt(i, 7).toString());
                
                int intTambah = pStatement.executeUpdate();
                if (intTambah>0){
                    //JOptionPane.showMessageDialog(this,
                    //        "Penambahan detail sukses", "Informasi",
                    //        JOptionPane.INFORMATION_MESSAGE);
                }else{
                    JOptionPane.showMessageDialog(this,
                            "Penambahan detail gagal", "Informasi",
                            JOptionPane.INFORMATION_MESSAGE);
                }
                pStatement.close();

            }catch(SQLException e){
                System.out.println("koneksi gagal " + e.toString());
            }
        }
        updateDataBrg();        
    }

    private void updateDataBrg(){
        PreparedStatement pStatement = null;
        String sql = "UPDATE tbrg " +
                    "SET bal=?, slop=?, bks=?  " +
                    "WHERE kdBrg=? ";

        int rows = tbTransaksi.getRowCount();
        for (int i=0; i< rows; i++) {
            try {
                pStatement = conn.prepareStatement(sql);

                //bal
                pStatement.setInt(1, aBal[i+1] - Integer.parseInt(tbTransaksi.getValueAt(i, 4).toString()));//bal
                //slop
                pStatement.setInt(2, aSlop[i+1] - Integer.parseInt(tbTransaksi.getValueAt(i, 5).toString()));//slop
                //bks
                pStatement.setInt(3, aBks[i+1] - Integer.parseInt(tbTransaksi.getValueAt(i, 6).toString()));//bks

                pStatement.setString(4, tbTransaksi.getValueAt(i, 1).toString());//kdbrg
                System.out.println("kode barang : " + tbTransaksi.getValueAt(i, 1).toString());
                System.out.print("bal : " + aBal[i+1] + " - " + tbTransaksi.getValueAt(i, 4).toString());
                System.out.print(" slop : " + aSlop[i+1] + " - " + tbTransaksi.getValueAt(i, 5).toString());
                System.out.println(" bks : " + aBks[i+1] + " - " + tbTransaksi.getValueAt(i, 6).toString());
                int intTambah = pStatement.executeUpdate();

                if (intTambah >0){
                    //System.out.println("kode barang : " + tbTransaksi.getValueAt(i, 1).toString());
                    //JOptionPane.showMessageDialog(this,
                    //        "Update sukses", "Informasi",
                    //        JOptionPane.INFORMATION_MESSAGE);

                }else {
                    //JOptionPane.showMessageDialog(this,
                    //        "Edit gagal", "Informasi",
                    //       JOptionPane.INFORMATION_MESSAGE);
                }

                pStatement.close();

            } catch(SQLException e){
                System.out.println("koneksi gagal " + e.toString());
            }

        }
        kosongkanNew();
    }

    
    
    private void editData(){
         //nomor ieu mah
        //String sKdGol = tbBarangGol.getValueAt(
               // tbBarangGol.getSelectedRow(), 0).toString();

        try {
            PreparedStatement pStatement = null;
            String sql = "UPDATE tbrg_gol " +
                    "SET nmGol=?, ket=? " +
                    "WHERE kdGol=? ";
            pStatement = conn.prepareStatement(sql);

            //pStatement.setString(1, cbKodeKota.getSelectedItem().toString());
            //pStatement.setString(1, txtKdGol.getText());
            pStatement.setString(1, txtNamaBrg.getText());
            //kd-/pStatement.setString(2, txtKet.getText());
            pStatement.setString(3, txtKdBrg.getText());

            int intTambah = pStatement.executeUpdate();
            if (intTambah >0){
                JOptionPane.showMessageDialog(this,
                        "Edit sukses", "Informasi",
                        JOptionPane.INFORMATION_MESSAGE);

            }else {
                JOptionPane.showMessageDialog(this,
                        "Edit gagal", "Informasi",
                        JOptionPane.INFORMATION_MESSAGE);
            }

            //tbBarangGol.get
            pStatement.close();
            kosongkan();
            //kd/tampilData();


        } catch(SQLException e){
            System.out.println("koneksi gagal " + e.toString());
        }
    }

    private void getDataFromBarang(){
        Object oKdBrg, oNmBrg;

        oKdBrg = tbBarang.getValueAt(tbBarang.getSelectedRow(), 1);
        oNmBrg = tbBarang.getValueAt(tbBarang.getSelectedRow(), 2);

        try {
            java.sql.Statement stmt = conn.createStatement();
            java.sql.ResultSet rslt = stmt.executeQuery("Select * from tbrg WHERE kdBrg=" +
                    "'" +oKdBrg+ "'");
            while (rslt.next()) {
                txtDiscBrgPrs.setText(rslt.getString("disc_prs"));
                txtDiscBrgRp.setText(rslt.getString("disc_rp"));
            }
        }
        catch(SQLException e) {
            System.out.println("gagal : " + e.toString());
        }
        
        txtKdBrg.setText(oKdBrg.toString());
        txtNamaBrg.setText(oNmBrg.toString());
        setHarga();

    }
    private void getDataFromPlg(){
                // TODO add your handling code here:
        Object oKdPlg, oNmPlg;//, oKet;//, oTest;

        oKdPlg = tbPlg.getValueAt(tbPlg.getSelectedRow(), 1);
        oNmPlg = tbPlg.getValueAt(tbPlg.getSelectedRow(), 2);

        try {
            java.sql.Statement stmt = conn.createStatement();
            java.sql.ResultSet rslt = stmt.executeQuery("Select * from tplg WHERE kdPlg=" +
                    "'" +oKdPlg+ "'");
            while (rslt.next()) {
                txtDiscPlgPrs.setText(rslt.getString("disc_prs"));
                txtDiscPlgRp.setText(rslt.getString("disc_rp"));
            }
        }
        catch(SQLException e) {
            System.out.println("gagal : " + e.toString());
        }
        
        txtKdPlg.setText(oKdPlg.toString());
        txtNamaPlg.setText(oNmPlg.toString());

        btnCariBrg.setEnabled(true);
    }

    private void setHarga(){
        Integer allStokBks=0, iBal=0, iSlop=0, iBks=0;
        String shrgKanvas = "";
        String shrgGrosir = "";
        String shrgStokis = "";
        if(!txtKdBrg.getText().equals("")){
        try {
            java.sql.Statement stmt = conn.createStatement();
            java.sql.ResultSet rslt = stmt.executeQuery(
                    "SELECT * FROM tbrg WHERE UPPER(kdBrg) like UPPER('%" +
                    txtKdBrg.getText() + "%')");
            //int iNo = 0;
            while (rslt.next()) {
                shrgKanvas = rslt.getString("hrgKanvas");
                shrgGrosir = rslt.getString("hrgGrosir");
                shrgStokis = rslt.getString("hrgStokis");
                iBal = rslt.getInt("bal");
                iSlop = rslt.getInt("slop");
                iBks = rslt.getInt("bks");
            }
        }
        catch(SQLException e) {
            System.out.println("gagal : " + e.toString());
        }
        if(cbTipeHarga.getSelectedItem().toString().equals("Kanvas")){
            txtHarga.setText(shrgKanvas);
        }else if(cbTipeHarga.getSelectedItem().toString().equals("Grosir")){
            txtHarga.setText(shrgGrosir);
        }else if(cbTipeHarga.getSelectedItem().toString().equals("Stokis")){
            txtHarga.setText(shrgStokis);
        }

        txtBalDB.setText(iBal.toString());
        txtSlopDB.setText(iSlop.toString());
        txtBksDB.setText(iBks.toString());

        }
        
    }   
    
    private void setKdJual(){
        String idJual = "";
        Integer noUrut = 0;
        try {
            java.sql.Statement stmt = conn.createStatement();
            java.sql.ResultSet rslt = stmt.executeQuery(
                    "SELECT * FROM tjual");
            //int iNo = 0;
            while (rslt.next()) {
                noUrut = rslt.getRow();
                idJual = rslt.getString("idJual");
            }
        }
        catch(SQLException e) {
            System.out.println("gagal : " + e.toString());
        }
        if(idJual.equals("")){
            idJual = "JL-0000000";
        }
        
        System.out.println(idJual);
        idJual = idJual.substring(3);
        System.out.println(idJual);      
        
        noUrut++;
        java.text.DecimalFormat nft = new java.text.DecimalFormat("#0000000.###");
        nft.setDecimalSeparatorAlwaysShown(false);
        System.out.println("JL-"+nft.format(noUrut));
        txtKdJual.setText("JL-"+nft.format(noUrut));
        
    }

    private void addData(){
        if(txtKdPlg.getText().equals("")) {
                JOptionPane.showMessageDialog(this, "Data tidak valid, " +
                        "data pelanggan harus terisi","Error",
                    JOptionPane.ERROR_MESSAGE);
        }else if(txtKdBrg.getText().equals("")){
                JOptionPane.showMessageDialog(this, "Data tidak valid, " +
                        "data barang harus terisi","Error",
                    JOptionPane.ERROR_MESSAGE);
        }else{
            if(validateNumber(txtBal.getText()) &&
               validateNumber(txtSlop.getText())&&
               validateNumber(txtBks.getText())){
                System.out.println("Correct Number");

                Integer iBal = Integer.parseInt(txtBal.getText());
                Integer iSlop = Integer.parseInt(txtSlop.getText());
                Integer iBks = Integer.parseInt(txtBks.getText());
                
                Integer iBalDB = Integer.parseInt(txtBalDB.getText());
                Integer iSlopDB = Integer.parseInt(txtSlopDB.getText());
                Integer iBksDB = Integer.parseInt(txtBksDB.getText());

                Integer allStokInput = (iBal * 200) + (iSlop * 10) + (iBks);
                Integer allStokDB = (iBalDB * 200) + (iSlopDB * 10) + (iBksDB);

                String kdTipe = "";                
                Integer iHarga = 0;
                Integer subtotal = 0;

                iHarga = Integer.parseInt(txtHarga.getText());
                subtotal =  ((iBal * 200) + (iSlop * 10) + (iBks)) * iHarga;
                kdTipe = Integer.toString(cbTipeHarga.getSelectedIndex());
                
                
                if(iBal >= 1 || iSlop >= 1 || iBks >= 1){
                    if(allStokDB >= allStokInput) {
                    //cek data sama
                    if(isSameKdBrg(txtKdBrg.getText())){
                        System.out.println("Sama!");                        
                        int rows = tbTransaksi.getRowCount();
                        for (int i=0; i< rows; i++) {
                        if(txtKdBrg.getText().equalsIgnoreCase(tbTransaksi.getValueAt(i, 1).toString())){
                            //update stok
                            iBal = iBal + Integer.parseInt(tbTransaksi.getValueAt(i, 4).toString());
                            tbTransaksi.setValueAt(iBal, i, 4);
                            iSlop = iSlop + Integer.parseInt(tbTransaksi.getValueAt(i, 5).toString());
                            tbTransaksi.setValueAt(iSlop, i, 5);
                            iBks = iBks + Integer.parseInt(tbTransaksi.getValueAt(i, 6).toString());
                            tbTransaksi.setValueAt(iBks, i, 6);
                            //update subtotal
                            subtotal = subtotal + Integer.parseInt(tbTransaksi.getValueAt(i, 7).toString());
                            tbTransaksi.setValueAt(subtotal, i, 7);
                        }
                        }
                    }else{
                        noItem = noItem + 1;
                        //"No","Kode","Nama Barang","Harga(Rp)","Bal","Slop","Bks","Total(Rp)"
                        String[] dataField = {Integer.toString(noItem), txtKdBrg.getText(), txtNamaBrg.getText(),
                        txtHarga.getText(),txtBal.getText(),txtSlop.getText(),txtBks.getText(),
                        Integer.toString(subtotal),kdTipe};
                        DftTabModeTr.addRow(dataField);
                    }
                    

                    int widths[] = {30, 120, 170, 100, 40, 40, 40, 100};
                    for(int i=0;i<tbTransaksi.getColumnCount();i++){
                        TableColumn column = tbTransaksi.getColumnModel().getColumn(i);
                        column.setPreferredWidth(widths[i]);
                    }
                    
                    //discount brg                    
                    if(!txtDiscBrgPrs.getText().equals("0")){
                        Float fdBrgPrs = Float.parseFloat(txtDiscBrgPrs.getText());
                        fdBrgPrs = fdBrgPrs / 100;// / 100 );
                        fdBrgPrs = fdBrgPrs * Float.parseFloat(iHarga.toString());
                        fdBrgPrs = fdBrgPrs * allStokInput;
                        
                        //int idBrg = (int)(fdBrgPrs + 0.5f);
                        int idBrg = (int)(fdBrgPrs + 0.5f);
                        iHDiskonBrg = iHDiskonBrg + idBrg;
                        System.out.println("DiscBrgPrs = " + iHDiskonBrg);
                    }else{
                        iHDiskonBrg = iHDiskonBrg + 
                                (Integer.parseInt(txtDiscBrgRp.getText()) * allStokInput);
                        System.out.println("DiscBrgRp = " + iHDiskonBrg);
                    }
                    

                    hitungHarga();
                    //4 STOK
                    aBal[noItem] = Integer.parseInt(txtBalDB.getText());
                    aSlop[noItem] = Integer.parseInt(txtSlopDB.getText());
                    aBks[noItem] = Integer.parseInt(txtBksDB.getText());
                    
                    kosongkan();
                    }else{
                        JOptionPane.showMessageDialog(this, "Data tidak valid, " +
                           "Jumlah barang yg dibeli melebihi kapasitas stok","Error",
                       JOptionPane.ERROR_MESSAGE);
                    }
                }else{
                    JOptionPane.showMessageDialog(this, "Data tidak valid, " +
                           "Bal, Slop, atau Bungkus harus diisi","Error",
                       JOptionPane.ERROR_MESSAGE);
                }                
            }else{
                System.out.println("Incorrect Number");
                JOptionPane.showMessageDialog(this, "Data tidak valid, " +
                        "Bal, Slop, atau Bungkus harus diisi Angka","Error",
                    JOptionPane.ERROR_MESSAGE);
            }
            
        }
        
    }
    public static boolean validateNumber(String num) {
        try {
            Integer.parseInt(num);
            return true;
        } catch (Exception e) {
            return false;
        }
       /*
     * if(validateNumber(num)){
            System.out.println("Correct Number");
        }else{
            System.out.println("Incorrect Number");
        }
     */
    }
    
    //format keluaran currency rupiah
    private String toRp(Integer iHarga){
        NumberFormat RupiahFormat = NumberFormat.getCurrencyInstance(new Locale("id", "ID"));
        return RupiahFormat.format(iHarga);
    }

    private void hitungKembali(){
        if(cbStatusBayar.getSelectedItem().toString().equals("Kredit")){
            iHDibayar = Integer.parseInt(txtHargaDibayar.getText());
            iHKembali = iHDibayar - iUangMuka;
            txtHargaKembali.setText(toRp(iHKembali));
        }else{
            iHDibayar = Integer.parseInt(txtHargaDibayar.getText());
            iHKembali = iHDibayar - iHAkhir;
            txtHargaKembali.setText(toRp(iHKembali));
        }
    }

    private void hitungSisaBayar(){
        iUangMuka = Integer.parseInt(txtUangMuka.getText());
        iSisaBayar = iHAkhir - iUangMuka;
        txtSisaBayar.setText(toRp(iSisaBayar));

        //iHDibayar = Integer.parseInt(txtHargaDibayar.getText());
        iHKembali = iHDibayar - iUangMuka;
        txtHargaKembali.setText(toRp(iHKembali));

    }

    private void hitungHarga(){
        iHTotal = 0; //buat lagi ke nol, soalnya diSum di tabel transaksi
        
        int rows = tbTransaksi.getRowCount();
        for (int i=0; i< rows; i++) {
            iHTotal = iHTotal + Integer.parseInt(tbTransaksi.getValueAt(i, 7).toString());
        }
        
        /*discount*/
        //pengurangan discount
        iHTotal2 = iHTotal - iHDiskonBrg;


        //discount Plg
        if(!txtDiscPlgPrs.getText().equals("0")){
            Float fdPlgPrs = Float.parseFloat(txtDiscPlgPrs.getText());
            fdPlgPrs = fdPlgPrs / 100;// / 100 );
            fdPlgPrs = fdPlgPrs * Float.parseFloat(iHTotal2.toString());
            
            int idPlg = (int)(fdPlgPrs + 0.5f);
            iHDiskonPlg = idPlg;
            System.out.println("DiscPlgPrs = " + iHDiskonPlg);
        }else{
            iHDiskonPlg =
            Integer.parseInt(txtDiscPlgRp.getText());
            System.out.println("DiscPlgRp = " + iHDiskonPlg);
        }

        iHAkhir = iHTotal2 - iHDiskonPlg;
        
        txtHargaTotal.setText(toRp(iHTotal));
        txtHargaDiscountBrg.setText(toRp(iHDiskonBrg));
        txtHargaTotal2.setText(toRp(iHTotal2));
        txtHargaDiscountPlg.setText(toRp(iHDiskonPlg));

        txtHargaAkhir.setText(toRp(iHAkhir));
        
    }

    private Date getDateTime(){
        DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
        Date date = new Date();
        return date;
        //return dateFormat.format(date);
    }

    private boolean isSameKdBrg(String x){
        int rows = tbTransaksi.getRowCount();
        boolean bKetemu = false;
        //tHarga = 0; //buat lagi ke nol, soalnya diSum di tabel transaksi
        for (int i=0; i< rows; i++) {
            //tHarga = tHarga + Integer.parseInt(tbTransaksi.getValueAt(i, 7).toString());
            if(x.equalsIgnoreCase(tbTransaksi.getValueAt(i, 1).toString())){
                bKetemu = true;
            }
        }
        return bKetemu;
    }

    private void hitungTxtSubTotal(){
        if(validateNumber(txtBal.getText()) &&
           validateNumber(txtSlop.getText()) &&
           validateNumber(txtBks.getText())){

           Integer iSub = 0;
           iSub = (Integer.parseInt(txtBal.getText()) * 200 * Integer.parseInt(txtHarga.getText()) ) +
                  (Integer.parseInt(txtSlop.getText()) * 10 * Integer.parseInt(txtHarga.getText()) ) +
                  (Integer.parseInt(txtBks.getText()) * Integer.parseInt(txtHarga.getText()) );

           txtSubtotal.setText(toRp(iSub));
        }else{
            txtSubtotal.setText("0");
        }
    }
}
